<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:constants className="com.blandware.atleap.webapp.util.questionnaire.QuestionnaireModuleWebConstants" var="QUESTION_ID_KEY" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />

<atleap:isUserInRole roles="questionnaire-answerOption-update" var="canUpdate" />
<atleap:isUserInRole roles="questionnaire-answerOption-view" var="canView" />
<atleap:isUserInRole roles="questionnaire-answerOption-delete" var="canDelete" />
<atleap:isUserInRole roles="questionnaire-answerOption-move" var="canMove" />

<c:set var="infoCells" value="1" />
<c:set var="constantButtonCells" value="0" />
<c:set var="additionalCells" value="0" />
<c:if test="${canUpdate}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canView}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canDelete}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canMove}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>

<atleap:content identifier="answerOptionsListInfo" ignore="true" />
<atleap:grid name="answerOptionGrid" pageSize="${pageSize}">
	<atleap:messages />
    <atleap:queryParameter name="questionId" value="${sessionScope[pageScope.QUESTION_ID_KEY]}" />
    <table border="0" cellpadding="0" cellspacing="0" class="grid">
        <thead>
            <tr>
                <th nowrap="nowrap">
                    <atleap:message key="questionnaire.answerOption.form.title" />
                </th>
                <c:if test="${constantButtonCells + additionalCells > 0}">
                    <th colspan="${constantButtonCells + additionalCells}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                </c:if>
             </tr>
        </thead>
        <tbody>
        	<atleap:contextMenu var="menuId">
				<atleap:rowsIterator beanId="questionnaireManager" method="listAnswerOptions" var="answerOption" oddClass="oddRow" evenClass="evenRow">
					<atleap:itemSet>
                        <atleap:rewriteUrl action="questionnaire/answerOption/view" var="defaultUrl">
                            <atleap:param name="id" value="${answerOption.id}" />
                        </atleap:rewriteUrl>
                        <c:set var="onTrClickCode" value="" />
                        <c:set var="tdClass" value="defaultCursorCell" />
                        <c:if test="${canView}">
                            <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                            <c:set var="tdClass" value="pointerCursorCell" />
                        </c:if>
						<tr class="${rowClass}" oncontextmenu="return showContextMenu(${menuId}, event, ${indexId});" onclick="${onTrClickCode}">
							<td class="${tdClass}">
                                <atleap:fieldValue valueMap="${answerOption.title}" filter="true" />
                            </td>
                            <c:if test="${canMove}">
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:item enabled="${!answerOption.question.questionnaire.fixed && answerOption.position > minPosition}">
                                        <atleap:message key="core.commons.buttons.moveUp" var="callMoveUpMsg" />
                                        <atleap:itemEnabled>
                                            <atleap:itemLink action="questionnaire/answerOption/move?id=${answerOption.id}&direction=up" title="${callMoveUpMsg}" transaction="true">
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/up.gif" />" border="0" title="${callMoveUpMsg}" alt="${callMoveUpMsg}"  align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callMoveUpMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemEnabled>
                                        <atleap:itemDisabled>
                                            <atleap:itemLink title="${callMoveUpMsg}">
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/upDisabled.gif" />" border="0" title="${callMoveUpMsg}" alt="${callMoveUpMsg}"  align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callMoveUpMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemDisabled>
                                    </atleap:item>
                                    <atleap:item enabled="${!answerOption.question.questionnaire.fixed && answerOption.position < maxPosition}">
                                        <atleap:message key="core.commons.buttons.moveDown" var="callMoveDownMsg" />
                                        <atleap:itemEnabled>
                                            <atleap:itemLink action="questionnaire/answerOption/move?id=${answerOption.id}&direction=down" title="${callMoveDownMsg}" transaction="true">
                                                <img class="betweenImg" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/down.gif" />" border="0" title="${callMoveDownMsg}" alt="${callMoveDownMsg}"  align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callMoveDownMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemEnabled>
                                        <atleap:itemDisabled>
                                            <atleap:itemLink title="${callMoveDownMsg}">
                                                <img class="betweenImg" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/downDisabled.gif" />" border="0" title="${callMoveDownMsg}" alt="${callMoveDownMsg}"  align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callMoveDownMsg}
                                                </atleap:itemLabel>
                                            </atleap:itemLink>
                                        </atleap:itemDisabled>
                                    </atleap:item>
                                </td>
                            </c:if>
							<atleap:item enabled="${!answerOption.question.questionnaire.fixed}" includeInContextMenu="${canUpdate}" includeInPage="${canUpdate}">
                                <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
								<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
									<atleap:itemEnabled>
										<atleap:itemLink action="questionnaire/answerOption/callUpdate" title="${callUpdateMsg}">
											<atleap:param name="id" value="${answerOption.id}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" title="${callUpdateMsg}" alt="${callUpdateMsg}"  align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${callUpdateMsg}
                                                </atleap:itemLabel>
										</atleap:itemLink>
									</atleap:itemEnabled>
                                    <atleap:itemDisabled>
                                        <atleap:message key="questionnaire.answerOption.form.editDisabled" var="editDisabledMsg" />
                                        <atleap:itemLink title="${editDisabledMsg}">
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/editDisabled.gif" />" border="0" title="${editDisabledMsg}" alt="${editDisabledMsg}" align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${editDisabledMsg}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemDisabled>
								</td>
							</atleap:item>
							<atleap:item includeInContextMenu="${canView}" includeInPage="${canView}">
								<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
									<atleap:itemEnabled>
										<atleap:message key="core.commons.buttons.view" var="viewMsg"/>
										<atleap:itemLink action="questionnaire/answerOption/view" title="${viewMsg}">
											<atleap:param name="id" value="${answerOption.id}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}"  align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${viewMsg}
                                                </atleap:itemLabel>
										</atleap:itemLink>
									</atleap:itemEnabled>
								</td>
							</atleap:item>
							<atleap:item enabled="${!answerOption.question.questionnaire.fixed}" includeInContextMenu="${canDelete}" includeInPage="${canDelete}">
								<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
									<atleap:message key="core.commons.buttons.delete" var="deleteMsg"/>
									<atleap:itemEnabled>
										<atleap:itemLink action="questionnaire/answerOption/delete" transaction="true" confirmExpression="confirmDelete();" title="${deleteMsg}">
											<atleap:param name="id" value="${answerOption.id}" />
                                                <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/delete.gif" />" border="0" title="${deleteMsg}" alt="${deleteMsg}" align="absmiddle" />
                                                <atleap:itemLabel>
                                                    ${deleteMsg}
                                                </atleap:itemLabel>
										</atleap:itemLink>
									</atleap:itemEnabled>
                                    <atleap:itemDisabled>
                                        <atleap:message key="questionnaire.answerOption.form.deleteDisabled" var="deleteDisabledMsg" />
                                        <atleap:itemLink title="${deleteDisabledMsg}">
                                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/deleteDisabled.gif" />" border="0" title="${deleteDisabledMsg}" alt="${deleteDisabledMsg}" align="absmiddle" />
                                            <atleap:itemLabel>
                                                ${deleteDisabledMsg}
                                            </atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemDisabled>
								</td>
							</atleap:item>
						</tr>
					</atleap:itemSet>
				</atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
            </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <atleap:message key="core.grid.pager.title" />&nbsp;
                        <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                        <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                        <atleap:pagesIterator>
                            <atleap:page>${pageNumber}&nbsp;</atleap:page>
                            <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                        </atleap:pagesIterator>
                        <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                        <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
    <c:if test="${!requestScope.question.questionnaire.fixed}">
        <atleap:isUserInRole roles="questionnaire-answerOption-create">
            <atleap:form action="questionnaire/answerOption/callCreate" method="GET" validateOnSubmit="false">
                <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.create" /></atleap:submit>
            </atleap:form>
        </atleap:isUserInRole>
    </c:if>
</atleap:grid>
